package ahblue.cn.tanzi.ui.person;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;

import ahblue.cn.tanzi.R;
import ahblue.cn.tanzi.jmessage.im.util.DialogCreator;
import ahblue.cn.tanzi.jmessage.im.util.ToastUtil;
import ahblue.cn.tanzi.model.user.CodeModel;
import ahblue.cn.tanzi.model.user.LoginResultModel;
import ahblue.cn.tanzi.ui.base.BaseActivity;
import ahblue.cn.tanzi.ui.person.pay.PayDialog;
import ahblue.cn.tanzi.ui.person.pay.WAPayNode;
import ahblue.cn.tanzi.util.PinkJSON;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 充值界面
 * Created by fengdongfei on 2018/12/1.
 */

public class PayMoneyActivity extends BaseActivity {
    @BindView(R.id.etmoney)
    EditText etmoney;
    private Dialog mDialog;


    public static void into(Activity activity) {
        activity.startActivity(new Intent(activity, PayMoneyActivity.class));
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_pay_money);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.btn_back, R.id.tvok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.tvok:
                String bankCard = etmoney.getText().toString();
                if (TextUtils.isEmpty(bankCard)) {
                    ToastUtil.shortToast(this, "请输入金额");
                    return;
                }
                mDialog = DialogCreator.createLoadingDialog(this, "开始支付");
                mDialog.show();
                CodeModel.getOrderPayNo(PayMoneyActivity.this, bankCard, LoginResultModel.getToken(this), new CodeModel.DataVertifyListener() {

                    @Override
                    public void conver(String orderSn) {
                        WAPayNode.pay(PayMoneyActivity.this, LoginResultModel.getToken(PayMoneyActivity.this), orderSn, "wx_app", new WAPayNode.VertifyListener() {
                            @Override
                            public void conver(WAPayNode b) {
                                mDialog.dismiss();
                                Log.d("WAPayNode", "conver: "+ PinkJSON.toJSON(b));
                                if (b != null) {
                                    PayDialog pay = new PayDialog(PayMoneyActivity.this,b);
                                    pay.show();
                                }
                            }
                        });
                    }
                });
                break;
        }
    }
}
